package cn.yuanqiao.web.controller.cqbc;

import cn.yuanqiao.common.utils.poi.ExcelUtil;
import cn.yuanqiao.common.core.controller.BaseController;
import cn.yuanqiao.common.core.domain.AjaxResult;
import cn.yuanqiao.common.core.page.TableDataInfo;
import cn.yuanqiao.common.annotation.Log;
import cn.yuanqiao.common.enums.BusinessType;
import cn.yuanqiao.cqbc.dataManage.domain.Cqdatransdoc;
import cn.yuanqiao.cqbc.dataManage.domain.YqdatransdocLog;
import cn.yuanqiao.cqbc.dataManage.service.DocToOfdService;
import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 格式转换
 *
 * @ProjectName: cn.yuanqiao.cqbc.dataManage.controller
 * @ClassName: DocToOfdController
 * @Author: lenovo
 * @Description: hbWang
 * @Date: 2024/6/19 16:29
 * @Version: 1.0
 **/
@RestController
@RequestMapping("/cqbc/gszh")
public class DocToOfdController extends BaseController {
    @Autowired
    DocToOfdService docToOfdService;

    /**
     * ofd转换
     *
     * @param jsonObject categoryId  门类id
     *                   daIds  多个用逗号隔开
     * @return
     */
    @Log(title = "ofd转换", businessType = BusinessType.OTHER)
    @PostMapping("/docToOfd")
    public AjaxResult docToOfd(@RequestBody JSONObject jsonObject) {
        try {
            docToOfdService.docToOfd(jsonObject);
            return AjaxResult.success();
        } catch (Exception e) {
            e.getMessage();
        }
        return AjaxResult.error("转换失败");
    }

    /**
     * 查询转换日志列表
     *
     * @param yqdatransdocLog
     * @return
     */
    @GetMapping("/log/list")
    @Log(title = "查询转换记录列表", businessType = BusinessType.SELECT)
    public TableDataInfo loglist(YqdatransdocLog yqdatransdocLog) {
        startPage();
        List<YqdatransdocLog> list = docToOfdService.selectYqdatransdocLogList(yqdatransdocLog);
        return getDataTable(list);
    }

    /**
     * 导出转换日志列表
     *
     * @param response
     * @param yqdatransdocLog
     */
    @Log(title = "导出转换记录", businessType = BusinessType.EXPORT)
    @PostMapping("/log/export")
    public void exportlog(HttpServletResponse response, YqdatransdocLog yqdatransdocLog) {
        startPage();
        List<YqdatransdocLog> list = docToOfdService.selectYqdatransdocLogList(yqdatransdocLog);
        ExcelUtil<YqdatransdocLog> util = new ExcelUtil<YqdatransdocLog>(YqdatransdocLog.class);
        util.exportExcel(response, list, "转换记录");
    }

    /**
     * 查询转换日志详情列表
     *
     * @param cqdatransdoc
     * @return
     */
    @GetMapping("/logDatails/list")
    @Log(title = "查询转换日志详情列表", businessType = BusinessType.SELECT)
    public TableDataInfo logDatails(Cqdatransdoc cqdatransdoc) {
        startPage();
        List<Cqdatransdoc> list = docToOfdService.selectYqdatransdocList(cqdatransdoc);
        return getDataTable(list);
    }

    /**
     * 导出转换日志详情列表
     *
     * @param response
     * @param cqdatransdoc
     */
    @Log(title = "导出转换日志详情", businessType = BusinessType.EXPORT)
    @PostMapping("/logDatails/export")
    public void exportLogDatails(HttpServletResponse response, Cqdatransdoc cqdatransdoc) {
        startPage();
        List<Cqdatransdoc> list = docToOfdService.selectYqdatransdocList(cqdatransdoc);
        ExcelUtil<Cqdatransdoc> util = new ExcelUtil<Cqdatransdoc>(Cqdatransdoc.class);
        util.exportExcel(response, list, "转换日志详情");
    }


    /**
     * 删除查询转换记录详情
     *
     * @param id
     * @return
     */
    @Log(title = "删除查询转换记录详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/logDatails/del")
    public AjaxResult delYqdatransdoc(@RequestParam("id") String id) {
        return toAjax(docToOfdService.delYqdatransdoc(id));
    }

    /**
     * 删除转换记录
     *
     * @param id
     * @return
     */
    @Log(title = "删除转换记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/log/del")
    public AjaxResult delYqdatransdocLog(@RequestParam("id") String id) {
        return toAjax(docToOfdService.delYqdatransdocLog(id));
    }
}
